#include <bits/stdc++.h>

using namespace std;

class Solution {
public:
	string decodeString(string s)
	{
		stack<int> num_stack;
		stack<string> str_stack;
		string res;
		int multi { 0 };

		for (char ch : s) {
			switch (int cond { trans(ch) }; cond) {
			case 1:
				multi = multi * 10 + ch - '0';
				break;
			case 2:
				str_stack.emplace(res);
				num_stack.emplace(multi);
				res.clear();
				multi = 0;
				break;
			case 3:
				res.push_back(ch);
				break;
			case 4:
				string temp = str_stack.top(); str_stack.pop();
				int num = num_stack.top(); num_stack.pop();
				for (int i = 0; i < num; i++)
					temp += res;
				res = temp;
				break;
			}
		}

		return res;
	}

private:
	int trans(char ch)
	{
		if (isdigit(ch))
			return 1;
		else if (ch == '[')
			return 2;
		else if (isalpha(ch))
			return 3;
		else
			return 4;
	}
};

int main()
{
	Solution solution;
	return 0;
}
